package main.java.com.chankudo.thread;
/**
 * 直接继承Thread类，实现多线程的简单示例。
 */
public class SimpleThread extends Thread{
    public static final int DELAY = 10;

    public SimpleThread(String threadName) {
        this.setName(threadName);
    }

    @Override
    public void run() {
        //super.run();
        System.out.println("start running a thread:" + this.getName());
        try {
            Thread.sleep((int)(DELAY*Math.random()));
        } catch (InterruptedException e) {
            // 调用sleep或wait，线程被阻塞，此时如果接到中断信号就会进入到这个异常处理中。
            e.printStackTrace();
        }
        System.out.println("end running a thread:" + this.getName());
    }

    public static void main(String[] args) {
        for(int i = 0 ; i < 10 ; i++){
            SimpleThread thread = new SimpleThread("thread-"+i);
            thread.start();
        }
    }
    
}
